package com.pkk.penguin.frame.know.boot.schedule.hbsl;

import static com.pkk.penguin.frame.know.boot.config.handle.hbsl.HbslClassContent.CLASS_CONTAINER;
import static com.pkk.penguin.frame.know.boot.config.handle.zhiyi.synch.ZySynchContent.AUTH_USER_SET;

import com.alibaba.fastjson.JSONObject;
import com.pkk.penguin.frame.know.boot.bo.hbsl.MessageType;
import com.pkk.penguin.frame.know.boot.config.common.handle.AbstractWebSocketServer.WebScoketUtil;
import com.pkk.penguin.frame.know.boot.config.handle.hbsl.HbslWebSocketServer;
import com.pkk.penguin.frame.know.boot.config.handle.zhiyi.synch.ZySynchWebSocketServer;
import com.pkk.penguin.frame.know.boot.service.hbsl.HbslStudyService;
import javax.annotation.Resource;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Component;

/**
 * @description: 华北水利的定时任务操作
 * @author: peikunkun
 * @create: 2020-05-13 11:59
 **/
@Component
public class HbslScheduleConfig {


  @Resource
  private HbslStudyService hbslStudyService;
  @Resource
  private HbslWebSocketServer hbslWebSocketServer;
  @Resource
  private ZySynchWebSocketServer zySynchWebSocketServer;

  /**
   * @Description: 实时在线数据的展示
   * @return: void
   * @Author: peikunkun
   * @Date: 2020/5/13 0013 下午 12:01
   */
  @Scheduled(cron = "0/30 * * * * ?")
  public void online() {
    StringBuffer onlineLogByHbsl = new StringBuffer();
    onlineLogByHbsl.append("当前在线人数:[").append(hbslWebSocketServer.getOnlineCount()).append("]\n");
    onlineLogByHbsl.append("当前支持课程:[").append(JSONObject.toJSONString(CLASS_CONTAINER)).append("]\n");
    WebScoketUtil.broadcost(hbslWebSocketServer.getWebSocket(), MessageType.ONLINE, onlineLogByHbsl.toString());

    StringBuffer onlineLogByZhiyi = new StringBuffer();
    onlineLogByZhiyi.append("当前在线人数:[").append(zySynchWebSocketServer.getOnlineCount()).append("]\n");
    onlineLogByZhiyi.append("当前登录用户:[").append(JSONObject.toJSONString(JSONObject.toJSONString(AUTH_USER_SET)))
        .append("]\n");
    WebScoketUtil.broadcost(zySynchWebSocketServer.getWebSocket(), MessageType.ONLINE, onlineLogByZhiyi.toString());
  }


  /**
   * @Description: 开始学习
   * @return: void
   * @Author: peikunkun
   * @Date: 2020/5/13 0013 下午 3:14
   */
  @Scheduled(cron = "0 0/1 * * * ?")
  public void actionStudy() {
    hbslStudyService.handleStudy();
  }


}
